dom-capture
Library for scripts that run in the browser and extract information from web pages.
Installing
npm install @applitools/dom-capture
Using the package
This package exports 2 types of functions:
-
Functions that can be used when working with puppeteer, CDP or Selenium in Node.js:
getProcessPageScript
getProcessPageAndSerializeScript
getCaptureDomScript
These async functions return a string with a function that can be sent to the browser for evaluation. It doesn't immediately invoke the function, so the sender should wrap it as an IIFE. For example:
const {getProcessPageScript} = require('@applitools/dom-capture');
const processPageScript = await getProcessPageScript();
const returnValue = await page.evaluate(`(${processPageScript})()`);
-
The non bundled version of the scripts:
processPage
processPageAndSerialize
These functions can then be bundled together with other client-side code so they are consumed regardless of a browser driver (this is how the Eyes.Cypress SDK uses it).
Usage from non-JavaScript code
This package's dist
folder contains scripts that can be sent to the browser regradless of driver and language. An agent that wishes to extract information from a webpage can read the contents of dist/processPageAndSerialize
and send that to the browser as an async script. There's still the need to wrap it in a way that invokes it.
For example in Java
:
Object response = driver.executeAsyncScript("const callback = arguments[arguments.length - 1];(" + processPageAndSerialize + ")().then(callback, err => callback(err.message))";